﻿using SiliconSelect.BLL;
using SiliconSelect.DAL.DataEntity;
using SiliconSelect.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SiliconSelect.Views.UserOperatorDialog
{
    /// <summary>
    /// PermissionCheck.xaml 的交互逻辑
    /// </summary>
    public partial class PermissionCheck : Window
    {
        PermissionCheckViewModel viewModel = new PermissionCheckViewModel();
        public PermissionCheck()
        {
            InitializeComponent();
            DataContext = viewModel;
        }

        /// <summary>
        /// 点击确定之后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCommitClick(object sender, RoutedEventArgs e)
        {
            string? userName = viewModel.PermissionUser.Username;
            string? password = viewModel.PermissionUser.Password;
            DataResult<UserEntity> checkRes = LocalDataAccess.CheckUserInfo(userName!, password!);
            if (checkRes.State)
            {
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误,权限不够!", "权限认证失败提示框", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void BtnCancelClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
